package com.czy.util.json;

import com.czy.convert.Converter;
import com.czy.util.time.TimeFormat;
import com.czy.util.time.TimeUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;


public class DeserializerStr2LocalDateTime extends JsonDeserializer<LocalDateTime> implements Converter<String, LocalDateTime> {
    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        return convert(p.getText());
    }

    @Override
    public LocalDateTime convert(String source) {
        return TimeUtil.str2Time(source, TimeFormat.yyyy_MM_dd_HH_mm_ss_SSS).orElse(null);
    }
}
